using UnityEngine;
using System.Collections;

public class WowadiusSmallBullet : MonoBehaviour
{
	#region Public properties
	public int ShootAngle = 0;
	public GameObject CollideSpark = null;
	public GameObject ShootSpark = null;
	public AudioClip ShootSFX = null;
	public AudioClip CollideSFX = null;
	#endregion

	#region Private fields
	private const int POWER = 1;
	#endregion

	// Use this for initialization
	void Awake ()
	{
		//Shoot
		float shootAngleRad = ShootAngle * Mathf.Deg2Rad;
		float verticalForce = Mathf.Sin (shootAngleRad) * WowadiusGlobal.CurrentPlayerStats.BulletForce;
		float horzontalForce = Mathf.Cos (shootAngleRad) * WowadiusGlobal.CurrentPlayerStats.BulletForce;
		rigidbody.AddForce (new Vector3 (horzontalForce, verticalForce, 0));
		//Play shoot SFX
		AudioSource.PlayClipAtPoint (ShootSFX, transform.position, 0.3f);
		//Shoot spark
		Instantiate (ShootSpark, transform.position + new Vector3 (0, - 0.4f, 0), Quaternion.identity);
	}

	/// <summary>
	/// Collide with other
	/// </summary>
	/// <param name="collision">
	/// A <see cref="Collision"/>
	/// </param>
	void OnCollisionEnter (Collision collision)
	{
		//Play ricochet collide SFX
		AudioSource.PlayClipAtPoint (CollideSFX, transform.position);
		//Istantiate collide spark
		Instantiate (CollideSpark, transform.position, Quaternion.identity);
		//Destroy the bullet
		Destroy (gameObject);
		//Send message to other colliders
		foreach (ContactPoint contact in collision.contacts) {
			//Only send to non-player contacts
			if (!contact.otherCollider.name.Equals ("Player"))
				contact.otherCollider.SendMessage (WowadiusConstant.CustomMessage.TAKING_DAMAGE, POWER);
		}
	}
}
